<script setup lang="ts">
import { getHomeGoodsGuessLikeAPI } from '@/services/home'
import type { PageParams } from '@/types/global'
import type { GuessItem } from '@/types/home'
import { onMounted,ref } from 'vue'
import { useI18n } from 'vue-i18n'
const { t,locale } = useI18n()
// 分页参数
const pageParams: Required<PageParams> = {
	page: 1,
	pageSize: 10,
}
// 猜你喜欢的列表
const guessList = ref<GuessItem[]>([])
// 已结束标记
const finish = ref(false)
// 获取猜你喜欢数据
const getHomeGoodsGuessLikeData = async () => {
	// 退出分页判断
	if (finish.value === true) {
		return uni.showToast({ icon: 'none',title: t('no.more.data') + '~' })
	}
	const res = await getHomeGoodsGuessLikeAPI(pageParams)
	// guessList.value = res.result.items
	// 数组追加
	guessList.value.push(...res.result.items)
	// 分页条件
	if (pageParams.page < res.result.pages) {
		// 页码累加
		pageParams.page++
	} else {
		finish.value = true
	}
}
// 重置数据
const resetData = () => {
	pageParams.page = 1
	guessList.value = []
	finish.value = false
}
// 组件挂载完毕
onMounted(() => {
	getHomeGoodsGuessLikeData()
})
// 暴露方法
defineExpose({
	resetData,
	getMore: getHomeGoodsGuessLikeData,
})
</script>

<template>
	<view class="order-">
		<view v-for="item in guessList" :key="item.id" class="item-line flex-rbt">
			<view class="line-time">2024-06-21</view>
			<view class="line-price">21</view>
			<view class="line-state">支付</view>
			<view class="line-detail">详情详</view>
		</view>
	</view>
	<view class="loading-text">
		{{ finish ? t('no.more.data') + '~' : t('more.loading') + '...' }}
	</view>
</template>

<style lang="scss">
:host {
	display: block;
}

.order- {
	.item-line {
		border-bottom: 1rpx solid #ccc;
		padding-top: 21rpx;
		padding-bottom: 21rpx;
		font-size: 30rpx;
		color: #333;

		.line-time {
			width: 35%;
			text-align: center;
		}

		.line-price {
			width: 15%;
			text-align: center;
		}

		.line-state {
			width: 15%;
			text-align: center;
		}

		.line-detail {
			width: 35%;
			text-align: center;
		}
	}
}

// 加载提示文字
.loading-text {
	text-align: center;
	font-size: 28rpx;
	color: #666;
	padding: 20rpx 0;
}
</style>
